package logic

import (
	"context"
	"errors"
	"house_srv/models/mysql"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HousePictureLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHousePictureLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HousePictureLogic {
	return &HousePictureLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HousePictureLogic) HousePicture(in *house.HousePictureRequest) (*house.HousePictureResponse, error) {
	// todo: add your logic here and delete this line
	p := mysql.Picture{
		HouseId:    in.HouseId,
		HouseName:  in.HouseName,
		HouseCover: in.HouseCover,
	}
	err := p.Create()
	if err != nil {
		logx.Error("房源图片添加失败")
		return nil, errors.New("房源图片添加失败")
	}
	return &house.HousePictureResponse{
		PictureId: int64(p.ID),
	}, nil
}
